package mysql.cs.packet;

import common.Util.ByteUtil;
import mysql.MysqlPacket;

import java.io.IOException;

/**
 * lenenc_str     catalog
 * lenenc_str     schema
 * lenenc_str     table
 * lenenc_str     org_table
 * lenenc_str     name
 * lenenc_str     org_name
 * lenenc_int     length of fixed-length fields [0c]
 * 2              character set
 * 4              column length
 * 1              type
 * 2              flags
 * 1              decimals
 * 2              filler [00] [00]
 *   if command was COM_FIELD_LIST {
 * lenenc_int     length of default-values
 * string[$len]   default values
 *   }
 */
public class QueryResField41Packet extends MysqlPacket {
    private String catalog;
    private String schema;
    private String table;
    private String orgTable;
    private String name;
    private String orgName;
    private int characterSet;
    private long columnLength;
    private byte type;
    private int flags;
    private byte decimals;
    private String defaultValue;
    public void encode(byte[] data) throws IOException {
        int index=0;
        //default UTF8
        ByteUtil.LengthCodedStringReader stringReader=new ByteUtil().getNewLengthCodedStringReaderUTF8IDX0();
        catalog=stringReader.readLengthCodedString(data);
        schema=stringReader.readLengthCodedString(data);
        table=stringReader.readLengthCodedString(data);
        orgTable=stringReader.readLengthCodedString(data);
        name=stringReader.readLengthCodedString(data);
        orgName=stringReader.readLengthCodedString(data);
        index=stringReader.getIndex();
        //length of fixed-length fields [0c]
        index++;
        characterSet=ByteUtil.readUnsignedShortLittleEndian(data,index);
        index+=2;
        columnLength=ByteUtil.readUnsignedIntLittleEndian(data,index);
        index+=4;
        type=data[index];
        index++;
        flags=ByteUtil.readUnsignedShortLittleEndian(data,index);
        index+=2;
        decimals=data[index];
        index++;
        //
        index+=2;
        //COM_FIELD_LIST
        if (index < data.length) {
            stringReader.setIndex(index);
            this.defaultValue = stringReader.readLengthCodedString(data);
        }

    }
    //不可能
    public byte[] decode(){
        return null;
    }

    public String getCatalog() {
        return catalog;
    }

    public void setCatalog(String catalog) {
        this.catalog = catalog;
    }

    public String getSchema() {
        return schema;
    }

    public void setSchema(String schema) {
        this.schema = schema;
    }

    public String getTable() {
        return table;
    }

    public void setTable(String table) {
        this.table = table;
    }

    public String getOrgTable() {
        return orgTable;
    }

    public void setOrgTable(String orgTable) {
        this.orgTable = orgTable;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getOrgName() {
        return orgName;
    }

    public void setOrgName(String orgName) {
        this.orgName = orgName;
    }

    public int getCharacterSet() {
        return characterSet;
    }

    public void setCharacterSet(int characterSet) {
        this.characterSet = characterSet;
    }

    public long getColumnLength() {
        return columnLength;
    }

    public void setColumnLength(long columnLength) {
        this.columnLength = columnLength;
    }

    public byte getType() {
        return type;
    }

    public void setType(byte type) {
        this.type = type;
    }

    public int getFlags() {
        return flags;
    }

    public void setFlags(int flags) {
        this.flags = flags;
    }

    public byte getDecimals() {
        return decimals;
    }

    public void setDecimals(byte decimals) {
        this.decimals = decimals;
    }

    public String getDefaultValue() {
        return defaultValue;
    }

    public void setDefaultValue(String defaultValue) {
        this.defaultValue = defaultValue;
    }


}

















